package com.jzqf.compose.ui

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController


sealed class Screen(val route: String) {
    object ScreenA : Screen("screen_a")
    object ScreenB : Screen("screen_b")
}

@Composable
fun NavGraphTest(startDestination: String = Screen.ScreenA.route) {
    val navController = rememberNavController()

    NavHost(navController, startDestination) {
        composable(Screen.ScreenA.route) {
            ScreenAContent(navController)
        }
        composable(Screen.ScreenB.route) {
            ScreenBContent(navController)
        }
    }
}

@Composable
fun ScreenAContent(navController: NavController) {
    Column(
        verticalArrangement = Arrangement.Center,
        horizontalAlignment = Alignment.CenterHorizontally,
        modifier = Modifier.padding(50.dp)
    ) {
        Text("This is Screen A")

        Button(onClick = { navController.navigate(Screen.ScreenB.route) }) {
            Text("Go to Screen B")
        }
    }
}

@Composable
fun ScreenBContent(navController: NavController) {
    Column(
        verticalArrangement = Arrangement.Center,
        horizontalAlignment = Alignment.CenterHorizontally,
        modifier = Modifier.padding(50.dp)
    ) {
        Text("This is Screen B")

        Button(onClick = { navController.navigateUp() }) {
            Text("Go back to Screen A")
        }
    }
}